home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / ai.prl / mike1.exe / FINDALL.PL < prev    next >
Encoding:
Text File  |  1990-07-14  |  2.6 KB  |  85 lines

  1. /* file: FINDALL.PL {hand-coded findall} */
  2. /*                          *************
  3.                                M I K E
  4.                             *************
  5.                Micro Interpreter for Knowledge Engineering
  6.                   {written in Edinburgh-syntax Prolog}
  7.  
  8. MIKE: Copyright (c) 1989, 1990 The Open University (U.K.)
  9.  
  10. MIKE is intended for educational purposes, and may not
  11. be sold as or incorporated in a commercial product without
  12. written permission from: The Copyrights Officer, Open University,
  13. Milton Keynes MK7 6AA, U.K.
  14.  
  15. The Open University accepts no responsibility for any legal or other
  16. consequences which may arise directly or indirectly as a result of the
  17. use of all or parts of the contents of this program.
  18.  
  19. This software accompanies Open University Study Pack PD624, 'KNOWLEDGE
  20. ENGINEERING'.  Complete sets of study pack materials may be obtained from:
  21.  
  22.                       Learning Materials Sales Office
  23.                       The Open University
  24.                       P.O. Box 188
  25.                       Milton Keynes MK7 6DH, U.K.
  26.  
  27.                       Tel: [+44] (908) 653338
  28.                       Fax: [+44] (908) 653744
  29. */
  30. /* findall/3 is not provided as a system primitive in some dialects,
  31.    so this file contains a hand-coded definition.
  32.  
  33.    findall1/3 is the analogous, except duplicates are removed
  34. */
  35.  
  36. /* unique stack-markers are needed in case you nest findall within findall */
  37.  
  38. unique_pd624_symbol(sym1).
  39. unique_pd624_symbol(sym2).
  40. unique_pd624_symbol(sym3).
  41. unique_pd624_symbol(sym4).
  42. unique_pd624_symbol(sym5).
  43. unique_pd624_symbol(sym6).
  44. unique_pd624_symbol(sym7).
  45. unique_pd624_symbol(sym8).
  46. unique_pd624_symbol(sym9).
  47. unique_pd624_symbol(sym10).
  48. unique_pd624_symbol(sym11).
  49. unique_pd624_symbol(sym12).
  50. unique_pd624_symbol(sym13).
  51. unique_pd624_symbol(sym14).
  52. unique_pd624_symbol(sym15).
  53. unique_pd624_symbol(sym16).
  54. unique_pd624_symbol(sym17).
  55. unique_pd624_symbol(sym18).
  56. unique_pd624_symbol(sym19).
  57. unique_pd624_symbol(sym20).
  58.  
  59.  
  60.  
  61. findall(X, Goal, Xlist) :-
  62.     retract(unique_pd624_symbol(Sym)),
  63.     !,
  64.     (call(Goal),
  65.     assertz(stack(Sym,X)),
  66.     fail;
  67.     assertz(stack(Sym,bottom))),
  68.     collect(Sym,Xlist),
  69.     assert(unique_pd624_symbol(Sym)).
  70.  
  71. findall1(X, Goal, Xlist) :-
  72.     retract(unique_pd624_symbol(Sym)),
  73.     !,
  74.     (call(Goal),
  75.     do_just_once((stack(Sym,X);assertz(stack(Sym,X)))),
  76.     fail;
  77.     assertz(stack(Sym,bottom))),
  78.     collect(Sym,Xlist),
  79.     assert(unique_pd624_symbol(Sym)).
  80.  
  81. collect(Sym,L) :-
  82.     retract(stack(Sym,X)), !,
  83.     (X == bottom, !, L = [];
  84.     L = [X | Rest], collect(Sym,Rest)).
  85.